aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/sujet/[slug].tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-12-18 11:56:59 +0100
committerArmand Philippot <git@armandphilippot.com>2023-12-18 11:56:59 +0100
commitd592085dc0fec023dd9f3437d4c756d402ed8c8f (patch)
tree9bba6873cefac197934ca41eed22b0b7054e3f60 /src/pages/sujet/[slug].tsx
parent67581629ea87162e6d47b39b867b37a9a50754aa (diff)
fix(pages): use dynamic imports for the table of contents
The ToCWidget relies on Javascript to display the headings. If JS is disabled in the browser, the widget is empty. For a better UX, we should use dynamic imports. Now, the ToC is only displayed when JS is enabled.
Diffstat (limited to 'src/pages/sujet/[slug].tsx')
-rw-r--r--src/pages/sujet/[slug].tsx11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx
index af78185..8f46677 100644
--- a/src/pages/sujet/[slug].tsx
+++ b/src/pages/sujet/[slug].tsx
@@ -1,6 +1,7 @@
/* eslint-disable max-statements */
import type { ParsedUrlQuery } from 'querystring';
import type { GetStaticPaths, GetStaticProps } from 'next';
+import dynamic from 'next/dynamic';
import Head from 'next/head';
import NextImage from 'next/image';
import { useRouter } from 'next/router';
@@ -15,7 +16,6 @@ import {
PageSidebar,
PageBody,
LoadingPage,
- TocWidget,
Spinner,
} from '../../components';
import {
@@ -49,6 +49,13 @@ import {
useTopicsList,
} from '../../utils/hooks';
+const Toc = dynamic(
+ async () => import('../../components').then((mod) => mod.TocWidget),
+ {
+ ssr: false,
+ }
+);
+
export type TopicPageProps = {
data: {
currentTopic: WPTopic;
@@ -169,7 +176,7 @@ const TopicPage: NextPageWithLayout<TopicPageProps> = ({ data }) => {
}}
/>
<PageSidebar>
- <TocWidget
+ <Toc
heading={<Heading level={2}>{messages.widgets.tocTitle}</Heading>}
tree={[
...tree,